import request from "@/utils/request";

/**
 * 结算页面-生成订单-根据购物车选中商品
 * @returns
 */
export const createOrder = () => {
  return request({
    method: "GET",
    url: `/member/order/pre`,
  });
};

/**
 * 结算页面-生成订单-根据订单中商品-再次购买
 * @returns
 */
export const repurchaseOrder = (orderId) => {
  return request({
    method: "GET",
    url: `/member/order/repurchase/${orderId}`,
  });
};

/**
 * 添加收货地址
 * @param {Object} form - 参考接口文档
 */
export const addAddress = (data) => {
  return request({
    method: "POST",
    url: `/member/address`,
    data,
  });
};

/**
 * 修改收货地址
 * @param {Object} form - 参考接口文档
 */
export const editAddress = (data) => {
  return request({
    method: "PUT",
    url: `/member/address/${data.id}`,
    data,
  });
};

/**
 * 结算页面-提交订单
 * @param {Object} params - 参考接口文档
 * @returns
 */
export const submitOrder = (data) => {
  return request({
    method: "POST",
    url: `/member/order`,
    data,
  });
};

/**
 * 获取订单详细
 * @param {String} orderId - 订单ID
 * @returns
 */
export const findOrderDetail = (orderId) => {
  return request({
    method: "GET",
    url: `/member/order/${orderId}`,
  });
};
/**
 * 获取订单列表
 * @param {String} page - 页码
 * @param {String} pageSize - 每页条数
 * @param {String} orderState - 订单状态，1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消，未传该参数或0为全部
 * @returns
 */
export const findOrderList = (
  params = { page: 1, pageSize: 10, orderState: 0 }
) => {
  return request({
    method: "GET",
    url: `/member/order/${orderId}`,
    params,
  });
};

/**
 * 取消订单
 * @param {String} orderId - 订单ID
 * @param {String} cancelReason - 取消原因
 * @returns
 */
export const cancelOrder = ({ orderId, cancelReason }) => {
  return request({
    method: "PUT",
    url: `/member/order/${orderId}/cancel`,
    data: cancelReason,
  });
};

/**
 * 删除订单
 * @param {String} orderId - 订单ID
 * @returns
 */
export const deleteOrder = (ids) => {
  return request({
    method: "DELETE",
    url: `/member/order`,
    data: ids,
  });
};

/**
 * 确认收货
 * @param {String} orderId - 订单ID
 * @returns
 */
export const confirmOrder = (orderId) => {
  return request({
    method: "PUT",
    url: `/member/order/${orderId}/receipt`,
  });
};

/**
 * 查询物流
 * @param {String} orderId - 订单ID
 * @returns
 */
export const logisticsOrder = (orderId) => {
  return request({
    method: "GET",
    url: `/member/order/${orderId}/logistics`,
  });
};
